#ifndef REPEATER_WIN
#define REPEATER_WIN
#include "Bar.h"
#include "CoolButton.h"
#include "UiInterface.h"
#include "Fsm.h"
#include "Ui.hpp"

typedef CWinTraits<WS_POPUP | WS_SYSMENU /*| WS_CAPTION   | WS_BORDER*/|WS_VISIBLE, WS_EX_TOPMOST /*| WS_EX_TOOLWINDOW*/> RepeaterWinTraits;
class MainWindow: public CWindowImpl< MainWindow, CWindow, RepeaterWinTraits>,
                  public Ui< MainWindow>
{
public:
    DECLARE_WND_CLASS(_T("REPEATER_WIN"))

    BEGIN_MSG_MAP_EX(RepeaterWindow)
        MSG_WM_CREATE(OnCreate)
        MSG_WM_CLOSE(OnClose)
        MSG_WM_DESTROY(OnDestroy)
        MSG_WM_NCHITTEST(OnNcHitTest)
        MSG_WM_PAINT(OnPaint)
        MSG_WM_DROPFILES(OnDropFiles)
        //MESSAGE_HANDLER(MCIWNDM_NOTIFYPOS, OnStep)
        //MESSAGE_HANDLER(MCIWNDM_NOTIFYMODE, OnNotifyMode)
        MSG_WM_HOTKEY(OnHotKey)
        MSG_WM_TIMER(OnTimer)
        //MSG_WM_DRAWITEM(OnDrawItem)
        MSG_WM_CONTEXTMENU(OnContextMenu)
        COMMAND_ID_HANDLER(IDB_CLOSE, OnCloseButtonClicked)
        REFLECT_NOTIFICATIONS()

    END_MSG_MAP()


    //TODO: remove this friend
    friend class ProgressBar;

    void OnHotKey(int nHotKeyID, UINT uModifiers, UINT uVirtKey);    
    //LRESULT CALLBACK OnNotifyMode(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled);
    void OnTimer(UINT_PTR nIDEvent);
    LRESULT CALLBACK OnStep(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& handled);
    LRESULT OnContextMenu(HWND WPARAM, CPoint point);
    MainWindow();
    void OnDropFiles(HDROP hDropInfo);
    void OnPaint(CDCHandle dc);
    UINT OnNcHitTest(CPoint point);
    LRESULT OnClose();
    LRESULT OnCloseButtonClicked( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled );
    LRESULT OnCreate(LPCREATESTRUCT lpcs);
    LRESULT OnDestroy();

    LRESULT OnDbClick( UINT WPARAM, CPoint point);

    void DrawFileName(const std::wstring& file_name);
    void StartTimer(){
        SetTimer(timerId_, 500);
    }
    void StopTimer(){
        KillTimer(timerId_);
    }

    ProgressBar bar_;

private:
    CRect rect_, bar_rect_, close_rect_, icon_rect_, title_rect_;
    ATOM hotkey_;

    PlayerFsm player_fsm_;

    static const int timerId_ = 199;
    CoolButton close_button_;
};

#endif
